//
//  CXHGroMoreNativeExpressAd.m
//  CXHAdSDK-GroMore
//
//  Created by 陈坤 on 2024/10/15.
//

#import "CXHGroMoreNativeExpressAd.h"

@interface CXHGroMoreNativeExpressAd ()<CXHAdSDKNativeExpressAdDelegate>

@property (nonatomic, strong) CXHAdSDKNativeExpressAd *nativeExpressAd;

@end

@implementation CXHGroMoreNativeExpressAd

- (void)loadNativeExpressAd:(NSString *)posid size:(CGSize)size controller:(UIViewController *)controller count:(int)count{
    if (_nativeExpressAd == nil) {
        self.nativeExpressAd = [[CXHAdSDKNativeExpressAd alloc]initWithAdSize:CGSizeMake(size.width, size.height)];
        self.nativeExpressAd.posId = posid;
        self.nativeExpressAd.delegate = self;
        self.nativeExpressAd.controller = controller;
    }
    
    [self.nativeExpressAd load:count];
}

#pragma mark - price
/**
 获取竞价价格，单位分，为0则表示不支持竞价，开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice{
    return [self.nativeExpressAd getBidPrice];
}
/**
 发送竞价成功上报
 @param price 赢价价格，单位分
 */
- (void)sendWinNotice:(NSInteger)price{
    [self.nativeExpressAd sendWinNotice:price];
}

/**
 发送竞价失败上报
 @param price 赢价价格，单位分
 */
- (void)sendLossNotice:(NSInteger)price{
    [self.nativeExpressAd sendLossNotice:price];
}

#pragma mark - CXHAdSDKNativeExpressAdDelegate
/**
 信息流广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                     adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *> *)adViewArray{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdSucessToLoad:adViewArray:)]) {
        [self.delegate CXHGroMore_nativeExpressAdSucessToLoad:nativeAd adViewArray:adViewArray];
    }
}

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                         error:(NSError *)error{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdFailToLoad:error:)]) {
        [self.delegate CXHGroMore_nativeExpressAdFailToLoad:nativeAd error:error];
    }
}

/**
 信息流广告渲染成功

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistSuccess:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdViewRenderOrRegistSuccess:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdViewRenderOrRegistSuccess:self.nativeExpressAd adView:adView];
    }
}

/**
 信息流广告渲染失败

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistFail:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdViewRenderOrRegistFail:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdViewRenderOrRegistFail:self.nativeExpressAd adView:adView];
    }
}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeExpressAd *)nativeAd
                     adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdClicked:adView:loadingPageURL:)]) {
        [self.delegate CXHGroMore_nativeExpressAdClicked:nativeAd adView:adView loadingPageURL:loadingPageURL];
    }
}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeExpressAd *)nativeAd
                   adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdClose:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdClose:nativeAd adView:adView];
    }
}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeExpressAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdExposure:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdExposure:nativeAd adView:adView];
    }
}

/**
 信息流广告展示上报
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposureReport:(CXHAdSDKNativeExpressAd *)nativeAd
                            adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdExposureReport:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdExposureReport:nativeAd adView:adView];
    }
}

/**
 信息流广告点击上报

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClickedReport:(CXHAdSDKNativeExpressAd *)nativeAd
                           adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdClickedReport:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdClickedReport:nativeAd adView:adView];
    }
}

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeExpressAd *)nativeAd
                              adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHGroMore_nativeExpressAdCloseLandingPage:adView:)]) {
        [self.delegate CXHGroMore_nativeExpressAdCloseLandingPage:nativeAd adView:adView];
    }
}

@end
